<template>
  <div>
    <van-card
      v-for="(item, index) in $store.state.cart_list"
      :key="index"
      :num="2"
      :price="item.originalPrice"
      desc="描述信息"
      :title="item.name"
      :thumb="item.pic"
      ><template #num>
        <van-stepper v-model="item.num" />
      </template>
      <template #desc>
        <van-checkbox name="xz" v-model="item.checked" @click="checkedAll"></van-checkbox>
      </template>
    </van-card>
    <van-submit-bar
      :price="$store.getters.price"
      button-text="提交订单"
      style="bottom: 55px"
    >
      <van-checkbox v-model="checked" @click="checkAll">全选</van-checkbox>
    </van-submit-bar>
  </div>
</template>
<script>
export default {
  data() {
    return {
      checked: false,
    };
  },
  methods: {
    checkAll() {
      this.$store.state.cart_list.filter((item) => {
        item.checked = this.checked;
      });
    },
    checkedAll() {
      let check = this.$store.state.cart_list.filter((item) => {
        return (item.checked == true);
      });
      if (this.$store.state.cart_list.length == check.length) {
        this.checked = true;
      } else {
        this.checked = false;
      }
    },
  },
  beforeRouteEnter(to, from, next) {
    // ...
    next((vm) => {
      if (vm.$store.state.token == "") {
        vm.$router.push("/app/login");
      }
    });
  },
};
</script>
<style lang="scss" scoped>
</style>